<table border="1" cellspacing="0" class="table" width="100%">
<tr><th>项目明细</th></tr>
</table>
<table border="1" cellspacing="0" class="table">
    <thead>
      <tr>
        <th>地区</th>
        <th>大区</th>
        <th>小区</th>
        <th>城市</th>
        <th>编码</th>
        <th>专营店</th>
        <th>项目编号</th>
        <th>项目名称</th>
        <th>标准动作</th>
        <th>活动类型</th>
        <th>项目定额</th>
        <th>预算总费用</th>
        <th>预算审核金额</th>
        <th>项目可用额度</th>
        <th>结算申请金额</th>
        <th>结算审核结果</th>
        <th>结算审核金额</th>
        <th>项目可结算金额[数据库]</th>
        <th bgcolor="red">项目可结算金额[错误]</th>
        <th bgcolor="green">项目可结算金额[正确]</th>
        <th>差额</th>
      </tr>
    </thead>
    <tbody>
    <?php
    $storeTotal = array();
    foreach($list as $k => $v): ?>
      <?php
      $errCanSettleMoney = min((float)$v['canUseMoney'], (float)$v['settleApply']);
      $okCanSettleMoney = min((float)$v['canUseMoney'], (float)$v['settleAudit']);
      if(!isset($storeTotal[$v['storeId']]) ){
        $storeTotal[$v['storeId']]['db'] = 0;
        $storeTotal[$v['storeId']]['err'] = 0;
        $storeTotal[$v['storeId']]['ok'] = 0;
        $storeTotal[$v['storeId']]['diff'] = 0;
      }
      $storeTotal[$v['storeId']]['db'] += $v['canSettleMoney'];
      $storeTotal[$v['storeId']]['err'] += $errCanSettleMoney;
      $storeTotal[$v['storeId']]['ok'] += $okCanSettleMoney;
      $storeTotal[$v['storeId']]['diff'] += ($errCanSettleMoney-$okCanSettleMoney);
      ?>
      <tr>
        <td><?=isset($allStoreList[$v['storeId']]) ? $allStoreList[$v['storeId']]['area'] : ''?></td>
        <td><?=isset($allStoreList[$v['storeId']]) ? $allStoreList[$v['storeId']]['region'] : ''?></td>
        <td><?=isset($allStoreList[$v['storeId']]) ? $allStoreList[$v['storeId']]['spsarea'] : ''?></td>
        <td><?=isset($allStoreList[$v['storeId']]) ? $allStoreList[$v['storeId']]['city'] : ''?></td>
        <td><?=isset($allStoreList[$v['storeId']]) ? $allStoreList[$v['storeId']]['coding'] : ''?></td>
        <td><?=isset($allStoreList[$v['storeId']]) ? $allStoreList[$v['storeId']]['storeName'] : ''?></td>
        <td><?php echo $v['id']; ?></td>
        <td><?php echo $v['projectName']; ?></td>
        <td><?php echo $v['actionTypeStr'] ?></td>
        <td><?php echo $v['eventTypeStr'].'-'.$v['eventClassStr'] ?></td>
        <td><?php echo $v['fixedMoney'] ?></td>
        <td><?php echo $v['budgetApply'] ?></td>
        <td><?php echo $v['budgetAudit'] ?></td>
        <td><?php echo $v['canUseMoney'] ?></td>
        <td><?php echo $v['settleApply'] ?></td>
        <td><?php echo $v['settleAuditStr'] ?></td>
        <td><?php echo $v['settleAudit'] ?></td>
        <td><?php echo $v['canSettleMoney'] ?></td>
        <td><?php echo $errCanSettleMoney ?></td>
        <td><?php echo $okCanSettleMoney ?></td>
        <td><?php echo $errCanSettleMoney-$okCanSettleMoney ?></td>
      </tr>
    <?php endforeach; ?>
    </tbody>
</table>

<table border="1" cellspacing="0" class="table" width="100%">
<tr><th>专营店汇总</th></tr>
</table>
<table border="1" cellspacing="0" class="table">
    <thead>
      <tr>
        <th>地区</th>
        <th>大区</th>
        <th>小区</th>
        <th>城市</th>
        <th>编码</th>
        <th>专营店</th>
        <th>项目可结算金额[数据库]</th>
        <th bgcolor="red">项目可结算金额[错误]</th>
        <th bgcolor="green">项目可结算金额[正确]</th>
        <th>差额</th>
      </tr>
    </thead>
    <tbody>
    <?php
    foreach ($storeTotal as $k => $v) {
    ?>
    <tr>
        <td><?=isset($allStoreList[$k]) ? $allStoreList[$k]['area'] : ''?></td>
        <td><?=isset($allStoreList[$k]) ? $allStoreList[$k]['region'] : ''?></td>
        <td><?=isset($allStoreList[$k]) ? $allStoreList[$k]['spsarea'] : ''?></td>
        <td><?=isset($allStoreList[$k]) ? $allStoreList[$k]['city'] : ''?></td>
        <td><?=isset($allStoreList[$k]) ? $allStoreList[$k]['coding'] : ''?></td>
        <td><?=isset($allStoreList[$k]) ? $allStoreList[$k]['storeName'] : ''?></td>
        <td><?php echo $v['db'] ?></td>
        <td><?php echo $v['err'] ?></td>
        <td><?php echo $v['ok'] ?></td>
        <td><?php echo $v['diff'] ?></td>
      </tr>
    <?php } ?>
    </tbody>
</table>